updating oE and_bits

Bitwise Operations

and_bits

<built-in> function and_bits(object a, object b) 

performs the bitwise AND operation on corresponding bits in two objects. A bit in the result will be 1 only if the corresponding bits in both arguments are 1.

Parameters:
  1. a : one of the objects involved
  2. b : the second object
Returns:

An object, whose shape depends on the shape of both arguments. Each atom in this object is obtained by bitwise AND between atoms on both objects.

Comments:

The arguments to this function may be atoms or sequences. The rules for operations on sequences apply. The atoms in the arguments must be representable as 32-bit numbers, either signed or unsigned.

If you intend to manipulate full 32-bit values, you should declare your variables as atom, rather than integer. Euphoria's integer type is limited to 31-bits.

Results are treated as signed numbers. They will be negative when the highest-order bit is 1.

To understand the binary representation of a number you should display it in hexadecimal notation. Use the %x format of printf. Using int_to_bits is an even more direct approach.

Example 1:
 a = and_bits(#0F0F0000, #12345678) 
-- a is #02040000 
Example 2:
 a = and_bits(#FF, {#123456, #876543, #2211}) 
-- a is {#56, #43, #11} 
Example 3:
 a = and_bits(#FFFFFFFF, #FFFFFFFF) 
-- a is -1 
-- Note that #FFFFFFFF is a positive number, 
-- but the result of a bitwise operation is interpreted 
-- as a signed 32-bit number, so it's negative. 
See Also:

or_bits, xor_bits, not_bits, int_to_bits

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu